home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
asm_msc1.arc
/
EX52.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-11-20
|
1KB
|
37 lines
TITLE Delete from Unordered List (EX52.ASM)
PAGE ,132
OUR_CODE SEGMENT PARA 'CODE'
PUBLIC DEL_UL
DEL_UL PROC FAR
ASSUME CS:OUR_CODE
CLD ;Make DF=0, to scan forward
PUSH BX ;Save scratch register BX
PUSH DI ; and starting address
MOV CX,ES:[DI] ;Fetch element count
ADD DI,2 ;Make DI point to 1st data el.
REPNE SCASW ;Value in the list?
JE DELETE ; If so, go delete it.
POP DI ; Otherwise, restore registers
POP BX
RET ; and exit.
;
; The following instructions delete an element from the list,
; as follows:
; (1) If the element lies at the end of the list,
; delete it by decreasing the element count by 1.
; (2) Otherwise, delete the element by moving all
; subsequent elements up by one position.
;
DELETE: JCXZ DEC_CNT ;If (CX) = 0, delete last el.
NEXT_EL: MOV BX,ES:[DI] ;Move one element up in list
MOV ES:[DI-2],BX
ADD DI,2 ;Point to next element
LOOP NEXT_EL ;Repeat until all els. moved
DEC_CNT: POP DI ;Decrease el. count by 1
DEC WORD PTR ES:[DI]
POP BX ;Restore contents of BX
RET ; and exit
DEL_UL ENDP
OUR_CODE ENDS
END DEL_UL